<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-Control" content="no-cache">
  <title>屏幕尺寸匹配计算器</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      height: 100vh;
      background: white;
      color: #1E1E1E;
      font-size: 16px;
    }
    body, div, select, input {
      box-sizing: border-box;
    }
    .card {
      padding: 24px; border-radius: 8px; border: 1px #D9D9D9 solid;
    }
    .row {
      align-self: stretch; display: flex; justify-content: space-between; align-items: flex-start;
    }
    .form-item {
      height: 75px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
    }
    .title {
      align-self: stretch; font-weight: bold;
    }
    .input-item {
      align-self: stretch; height: 45px; line-height: 45px; border-radius: 8px; border: 1px #D9D9D9 solid; outline: none; width: 100%;
      font-size: 16px;
    }
    select {
      padding: 12px 24px 12px 12px; 
    }
    input {
      padding: 0 0 0 16px;
    }
    button {
      height: 45px;
      padding: 10px 12px;
      background-color: #2C2C2C;
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 14px;
    }
    button:hover {
      opacity: .8;
    }
  </style>
</head>
<body>
  <div style="width: 780px; padding: 30px; display: inline-flex;gap: 10px;">
    <div class="card" style="flex: 0 0 350px; display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 24px;">
      <div class="row">
        <div class="form-item" style="flex: 0 0 65%;">
          <div class="title">主屏分辨率</div>
          <select class="input-item" name="baseRevoSelector" id="baseRevoSelector" title="主屏分辨率">
            <option value="4K">3840*2160(4K)</option>
            <option value="2K">2560*1440(2K)</option>
            <option value="2Kuw">3440*1440(带鱼屏)</option>
            <option value="1080">1920*1080</option>
            <option value="1080uw">2560*1080(带鱼屏)</option>
            <option value="720">1280*720</option>
          </select>
        </div>
        <div class="form-item" style="flex: 0 0 32%;">
          <div class="title">尺寸 (英寸)</div>
          <input class="input-item" type="text" name="baseInchInput" id="baseInchInput" value="27" title="主屏尺寸 (英寸)" placeholder="请输入" />
        </div>
      </div>
      <div class="row">
        <div class="form-item" style="flex: 0 0 65%;">
          <div class="title">副屏分辨率 : </div>
          <select class="input-item" name="targetRevoSelector" id="targetRevoSelector" title="副屏分辨率">
            <option value="1080">1920*1080</option>
            <option value="2K">2560*1440(2K)</option>
            <option value="2Kuw">3440*1440(带鱼屏)</option>
            <option value="4K">3840*2160(4K)</option>
            <option value="1080uw">2560*1080(带鱼屏)</option>
            <option value="720">1280*720</option>
          </select>
        </div>
        <button type="button" style="flex: 0 0 32%; align-self: flex-end;" onclick="calc()">计算尺寸</button>
      </div>
    </div>

    <div class="card" style="flex: 1">
      <div id="hint-def">根据输入参数计算合适的副屏尺寸</div>
      <div id="hint-err" style="display: none; color: red;"></div>
      <div id="result" style="display: none;font-size: 18px;font-weight: bold;line-height: 30px;">
        <div>主屏：<span id="re_baseRevo"></span>, <span id="re_baseInch"></span>寸</div>
        <div>副屏：<span id="re_targetRevo"></span></div>
        <div>适合的副屏尺寸为：<span id="re_targetInch" style="font-size: 24px;"></span> 寸</div>
        <div>可以考虑跟该尺寸相近的显示器</div>
      </div>
    </div>
  </div>
  <div style="width: 780px; padding: 0 30px 30px 30px; line-height: 24px;">
    <div style="font-weight: bolder;">此计算器的目的：</div>
    <div>当两个不同分辨率、不同尺寸的显示器组成多屏的时候，经常会遇到下图所示的问题</div>
    <div><img src="./example.png" alt="example" style="width: 50%;"></div>
    <div>在边缘移动鼠标时，由于两个屏幕的分辨率及物理尺寸不同，鼠标可能不会出现在你期望的位置</div>
    <div>通过计算，购买合适的屏幕，可以获得相对好一些的体验</div>
  </div>
</body>
<script>
  var models = {
    '4K': {
      width: 3840,
      height: 2160,
    },
    '2K': {
      width: 2560,
      height: 1440,
    },
    '2Kuw': {
      width: 3440,
      height: 1440,
    },
    '1080': {
      width: 1920,
      height: 1080,
    },
    '1080uw': {
      width: 2560,
      height: 1080,
    },
    '720': {
      width: 1280,
      height: 720,
    },
  }
  function calc () {
    var baseInch = Number(document.getElementById('baseInchInput').value)
    if (isNaN(baseInch)) {
      document.getElementById('hint-err').innerHTML = '请输入正确的主屏尺寸 (英寸)'
      document.getElementById('hint-def').style.display = 'none'
      document.getElementById('hint-err').style.display = 'block'
      document.getElementById('result').style.display = 'none'
      return
    }
    var base = models[document.getElementById('baseRevoSelector').value]
    base['inch'] = baseInch
    var target = models[document.getElementById('targetRevoSelector').value]

    var bevelingPixelPerInch = Math.sqrt(Math.pow(base.width, 2) + Math.pow(base.height, 2)) / base.inch
    target['inch'] = Math.sqrt(Math.pow(target.width, 2) + Math.pow(target.height, 2)) / bevelingPixelPerInch

    document.getElementById('re_baseRevo').innerHTML = base.width + '*' + base.height
    document.getElementById('re_baseInch').innerHTML = base.inch
    document.getElementById('re_targetRevo').innerHTML = target.width + '*' + target.height
    document.getElementById('re_targetInch').innerHTML = target.inch.toFixed(1)

    document.getElementById('hint-def').style.display = 'none'
    document.getElementById('hint-err').style.display = 'none'
    document.getElementById('result').style.display = 'block'
  }
</script>
</html>